package com.tfjybj.itoo.exam.provider.service.impl;

import com.dmsdbj.itoo.tool.base.service.impl.BaseServicePlusImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.OptionEntity;
import com.tfjybj.itoo.exam.model.OptionModel;
import com.tfjybj.itoo.exam.provider.dao.OptionDao;
import com.tfjybj.itoo.exam.provider.service.OptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * OptionService接口实现类
 * ${base}表
 *
 * @author 李青松
 * @version 2.0.0
 * @since 2.0.0 2018-11-01 08:55:53
 */
@Service("optionService")
@Slf4j
public class OptionServiceImpl extends BaseServicePlusImpl<OptionDao, OptionEntity> implements OptionService {

    //region 模板生成
    @Resource
    private OptionDao optionDao;

    @Override
    public PageInfo<OptionEntity> queryByLikeHistoryId(String historyId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(optionDao.queryLikeHistoryId(historyId));
    }


    //endregion

    /* **********************************以下为非模板生成的内容********************************* */


    @Override
    public List<OptionModel> queryById(String id){
        List<OptionEntity> optionEntityList = optionDao.queryByQuestionId(id);
        List<OptionModel> optionModelList = new ArrayList<>();
        for (OptionEntity entity:optionEntityList) {
//            String name = null;
//            try {
//                name = new String(entity.getOptionNameHtml(),"UTF-8");
//            } catch (UnsupportedEncodingException e) {
//                log.error("字符转换错误",e);
//            }
            OptionModel model = new OptionModel();
            BeanUtils.copyProperties(entity,model);
//            model.setOptionNameHtml(name);
            optionModelList.add(model);
        }
        return optionModelList;
    }



}
